package cn.edu.cug.cs.gtl.docsrv.auth.service.imp;

import cn.edu.cug.cs.gtl.docsrv.auth.dao.RoleDao;
import cn.edu.cug.cs.gtl.docsrv.auth.service.RoleService;
import cn.edu.cug.cs.gtl.mybatis.mapper.auth.AuthRole;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class RoleServiceImpl implements RoleService {
    @Autowired
    RoleDao roleDao;

    @Override
    public boolean insertRole(String authRoleJSON) {
        AuthRole authRole = JSON.parseObject(authRoleJSON, AuthRole.class);
        if(authRole!=null)
            return roleDao.insertRole(authRole);
        else
            return false;
    }

    @Override
    public boolean updateRole(String authRoleJSON) {
        AuthRole authRole = JSON.parseObject(authRoleJSON, AuthRole.class);
        if(authRole!=null)
            return roleDao.updateRole(authRole);
        else
            return false;
    }

    @Override
    public boolean deleteRole(String authRoleName) {
        return roleDao.deleteRole(authRoleName);
    }

    @Override
    public String getRole(String authRoleName) {
        AuthRole authRole = roleDao.getRole(authRoleName);
        return JSON.toJSONString(authRole);
    }
}
